Completed
Push — master ( 3b8b0c...578b04 )
by Michael
02:39
created

PluginBlockMenuItemDispatcher.js ➔ getMenuItem   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 10
rs 10
1
import { setBlockType } from 'prosemirror-commands';
2
import AbstractMenuItemDispatcher from './AbstractMenuItemDispatcher';
3
import { svgIcon } from '../MDI';
4
import MenuItem from '../MenuItem';
5
6
export default class PluginBlockMenuItemDispatcher extends AbstractMenuItemDispatcher {
7
    static isAvailable({ nodes }) {
8
        return !!nodes.dwplugin_block;
9
    }
10
11
    static getMenuItem({ nodes }) {
12
        if (!this.isAvailable({ nodes })) {
13
            throw new Error('Plugin block not available in schema!');
14
        }
15
        return new MenuItem({
16
            command: setBlockType(nodes.dwplugin_block),
17
            icon: svgIcon('puzzle'),
18
            label: 'Plugin block',
19
        });
20
    }
21
}
22